// src/models/User.ts
import { DataTypes, Model, Optional } from "sequelize";
import sequelize from "../config/db";
import Articles from "./Articles";
import ArticleTag from "./ArticleTag";

// 定义用户模型接口
interface TagsAttributes {
  id: number;
  name: string;
  status: number;
}

interface UserCreationAttributes extends Optional<TagsAttributes, "id"> {}

class Tags
  extends Model<TagsAttributes, UserCreationAttributes>
  implements TagsAttributes
{
  public id!: number;
  public name!: string;
  public status!: number;
}

/**
 *
 * @
 *
 */
Tags.init(
  {
    id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    name: {
      type: DataTypes.STRING(50),
      allowNull: false,
      validate: {
        notEmpty: true, // 不允许为空字符串
      },
    },
    status: {
      type: DataTypes.TINYINT(),
      defaultValue: 1, // 默认启用
    },
  },
  {
    tableName: "tags",
    sequelize, // sequelize 实例
    timestamps: true,
  }
);

export default Tags;
